<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class CompanyTires extends Page
{
       public $Image3 = null;
       public $lblPressurePsi = null;
       public $lblFreeReplace = null;
       public $lblFreeWarning = null;
       public $lblDriveReplace = null;
       public $lblDriveWarning = null;
       public $lblSteerWarning = null;
       public $lblSteerReplace = null;
       public $lblTread32nds = null;
       public $cmbLocation = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $JTSiteTheme1 = null;
       public $JTGroupFreeTagAxle = null;
       public $edFreeReplaceAt = null;
       public $Label7 = null;
       public $edFreeWarningAt = null;
       public $lblFreeWarningAt = null;
       public $JTGroupDriveAxle = null;
       public $edDriveReplaceAt = null;
       public $lblDriveReplaceAt = null;
       public $edDriveWarningAt = null;
       public $lblDriveWarningAt = null;
       public $JTGroupAxleSteer = null;
       public $edAxleReplaceAt = null;
       public $lblAxleReplaceAt = null;
       public $edAxleWarningAt = null;
       public $lblAxleWarningAt = null;
       public $JTGroupNewTireDefaults = null;
       public $lblLocation = null;
       public $edPressure = null;
       public $lblPressure = null;
       public $edTread = null;
       public $lblTread = null;

       function btnCancelClick($sender, $params)
       {
       redirect('vehicle_list.php?company_id='.$_SESSION['company_id']);
       }

       function btnSubmitClick($sender, $params)
       {


       $result=mysql_query("select * from company_tires_tbl where company_id='".$_SESSION['company_id']."'");
       $count=mysql_num_rows($result);
       if($count==0)
       {
       mysql_query("insert into company_tires_tbl (company_id,
       tread,
       pressure,
       location,
       steer_warning,
       steer_replace,
       drive_warning,
       drive_replace,
       free_warning,
       free_replace)

       Values('".$_SESSION['company_id']."',
       '".$this->edTread->Text."',
       '".$this->edPressure->Text."',
       '".$this->cmbLocation->getItemIndex()."',
       '".$this->edAxleWarningAt->Text."',
       '".$this->edAxleReplaceAt->Text."',
       '".$this->edDriveWarningAt->Text."',
       '".$this->edDriveReplaceAt->Text."',
       '".$this->edFreeWarningAt->Text."',
       '".$this->edFreeReplaceAt->Text."')") or die ("insert tires - " . mysql_error());
       }
       else
       {
       mysql_query("update company_tires_tbl set
       tread='".$this->edTread->Text."',
       pressure='".$this->edPressure->Text."',
       location='".$this->cmbLocation->getItemIndex()."',
       steer_warning='".$this->edAxleWarningAt->Text."',
       steer_replace='".$this->edAxleReplaceAt->Text."',
       drive_warning='".$this->edDriveWarningAt->Text."',
       drive_replace='".$this->edDriveReplaceAt->Text."',
       free_warning='".$this->edFreeWarningAt->Text."',
       free_replace='".$this->edFreeReplaceAt->Text."'
       where company_id='".$_SESSION['company_id']."'") or die ("update tires _ " . mysql_error());
       }
       redirect('vehicle_list.php?company_id='.$_SESSION['company_id']);
       }


       function CompanyTiresCreate($sender, $params)
       {

       $query = "select * from company_tires_tbl where company_id='".$_SESSION['company_id']."'";
       $result_show = mysql_query($query)or die("SELECT TIRES - " . mysql_error());
       $row= mysql_fetch_array($result_show);

       $this->edTread->Text = $row['tread'];
       $this->edPressure->Text = $row['pressure'];
       $this->edAxleWarningAt->Text = $row['steer_warning'];
       $this->edAxleReplaceAt->Text = $row['steer_replace'];
       $this->edDriveWarningAt->Text = $row['drive_warning'];
       $this->edDriveReplaceAt->Text = $row['drive_replace'];
       $this->edFreeWarningAt->Text = $row['free_warning'];
       $this->edFreeReplaceAt->Text = $row['free_replace'];

       $this->cmbLocation->ItemIndex = $row['location'];

       $this->cmbLocation->Clear();
       $result_location = mysql_query("select value from lookup_tire_tbl where company_id='".$_SESSION['company_id']."' AND category='locations'");

       while($row_location = mysql_fetch_array($result_location))
       {
       $this->cmbLocation->AddItem($row_location['value'], null, $row_location['value']);
       }



       $result_unit = mysql_query("select * from company_measures_tbl where company_id='".$_SESSION['company_id']."'");
       $row_unit = mysql_fetch_array($result_unit);
       $label_unit = $row_unit['system_measure'];
       if (($label_unit=='Metric Measurement (km, Liters, L100 km)') ||($label_unit=='U.K. Measurement (Miles, Litres, MPG)'))
        {
        $this->lblTread32nds->Caption = 'mm';
        $this->lblPressurePsi->Caption = 'kpa';
        $this->lblSteerWarning->Caption = 'mm';
        $this->lblSteerReplace->Caption = 'mm';
        $this->lblDriveWarning->Caption = 'mm';
        $this->lblDriveReplace->Caption = 'mm';
        $this->lblFreeWarning->Caption = 'mm';
        $this->lblFreeReplace->Caption = 'mm';
       }
       else
       {
        $this->lblTread32nds->Caption = '32nds';
        $this->lblPressurePsi->Caption = 'psi';
        $this->lblSteerWarning->Caption = '32nds';
        $this->lblSteerReplace->Caption = '32nds';
        $this->lblDriveWarning->Caption = '32nds';
        $this->lblDriveReplace->Caption = '32nds';
        $this->lblFreeWarning->Caption = '32nds';
        $this->lblFreeReplace->Caption = '32nds';
       }

       }

}

global $application;

global $CompanyTires;

//Creates the form
$CompanyTires=new CompanyTires($application);

//Read from resource file
$CompanyTires->loadResource(__FILE__);

//Shows the form
$CompanyTires->show();

?>